<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>todolist</h1>
        <div>
            <input type="text" v-model="ipt" @keyup.enter="addBtn" autofocus>
            <button @click="addBtn">添加</button>
        </div>

        <h3>没有完成的项目</h3>
        <div v-for="(item,index) in arr1">
            <label for=""><input type="checkbox" :value="item" @click="fnished(index,$event)"> {{item}}</label>
            <button @click="delete1(index)">删除</button>
        </div>

        <h3>已经完成的项目</h3>
        <div v-for="(item,index) in arr2" @click="unfnished(index,$event)">
            <label for=""><input type="checkbox" :value="item" checked> {{item}}</label>
            <button @click="delete2(index)">删除</button>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <script>
        let vm = new Vue({
            el: "#app",
            data: {
                ipt: "",
                arr1: [],
                arr2: []
            },
            methods: {
                addBtn() {
                    if (this.ipt == "") return;
                    this.arr1.push(this.ipt);
                    this.ipt = "";
                },
                fnished(idx, e) {
                    if (e.target.checked) {
                        this.arr2.push(this.arr1[idx]);
                        this.arr1.splice(idx, 1);
                        e.target.checked = false;
                    }
                },
                unfnished(idx, e) {
                    if (!e.target.checked) {
                        this.arr1.push(this.arr2[idx]);
                        this.arr2.splice(idx, 1);
                        e.target.checked = true;
                    }
                },
                delete1(idx) {
                    this.arr1.splice(idx, 1)
                },
                delete2(idx) {
                    this.arr2.splice(idx, 1)
                }
            }
        })
    </script>
</body>

</html>